package com.atzly.community.service.impl;

import com.atzly.community.constant.CommentConstant;
import com.atzly.community.entity.Message;
import com.atzly.community.mapper.MessageMapper;
import com.atzly.community.service.MessageService;
import com.atzly.community.utils.SensitiveFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zlysimida
 * @date 2021/8/29 - 19:07
 */
@Service
public class MessageServiceImpl implements MessageService {

    @Autowired
    private MessageMapper messageMapper;

    @Autowired
    private SensitiveFilter sensitiveFilter;

    @Override
    public List<Message> getAllMessagePage(int userId, int offset, int limit) {
        return messageMapper.getAllMessagePage(userId,offset,limit);
    }

    @Override
    public int getMessagePageCounts(int userId) {
        return messageMapper.getMessagePageCounts(userId);
    }

    @Override
    public List<Message> getLetter(String conversationId, int offset, int limit) {
        return messageMapper.getLetter(conversationId,offset,limit);
    }

    @Override
    public int getLetterCount(String conservationId) {
        return messageMapper.getLetterCount(conservationId);
    }

    @Override
    public int getNoReadLetterCount(int userId, String conversationId) {
        return messageMapper.getNoReadLetterCount(userId,conversationId);
    }

    @Override
    public int insertMessage(Message message) {
        String filter = sensitiveFilter.filter(message.getContent());
        message.setContent(filter);
        return messageMapper.insertMessage(message);
    }

    @Override
    public int updateMessageStatus(List<Integer> ids) {
        // 将状态改为已读
        return messageMapper.updateMessageStatus(ids, CommentConstant.LETTER_STATUS_READ);
    }


    @Override
    public Message selectSystemLatestNotify(int userId, String topic) {
        return messageMapper.selectSystemLatestNotify(userId,topic);
    }

    @Override
    public int selectSystemNotifyCount(int userId, String topic) {
        return messageMapper.selectSystemNotifyCount(userId,topic);
    }

    @Override
    public int selectSystemNoReadNotify(int userId, String topic) {
        return messageMapper.selectSystemNoReadNotify(userId,topic);
    }

    @Override
    public List<Message> selectDetailsNotifyAndPage(int id, String topic, int offset, int limit) {
        return messageMapper.selectDetailsNotifyAndPage(id,topic,offset,limit);
    }
}
